<?php
namespace app\index\controller;

use think\Config;
use think\Db;

class Wxtrade
{
    public function wxPay()
    {
        vendor("wxPayReturn.WxPay_Config");
        vendor("wxPayReturn.WxPay_Api");

        if (isset($_REQUEST["out_trade_no"]) && $_REQUEST["out_trade_no"] != "") {
            $out_trade_no = $_REQUEST["out_trade_no"];
            $input = new \WxPayOrderQuery();
            $input->SetOut_trade_no($out_trade_no);
            $config = new \WxPayConfig();
            $WxPayApi=new \WxPayApi();
            $re = $WxPayApi->orderQuery($config, $input);
            if ($re['result_code'] == 'SUCCESS') {
                if ($re['trade_state'] == 'SUCCESS') {
                    $re = array(
                        'status' => 200,
                        "msg" => "请求成功!",
                        "data" => array(
                            "out_trade_no" => $_REQUEST['out_trade_no'],
                            "wechat_trade_status" => "WAIT_BUYER_PAY"
                        )
                    );
                    return json_encode($re);
                }
            }
            $re = array(
                'status' => 400,
                "msg" => "查询失败",
            );
            return json_encode($re);
        } else {
            $re = array(
                'status' => 400,
                "msg" => "数据缺失",
            );
            return json_encode($re);
        }

    }


}